\documentclass{article}
\usepackage{amsmath}
\begin{document}

%% in-text formula, use \(..\), $..$, \begin{math} .. \end{math}
%% in-text formula

%% if $\alpha = 2$, then $\alpha^3=8$



%% %% display formula, use \[..]\, \begin{displaymath} .. \end{displaymath}
%% display formula

%% \[
%% \lim_{n \to \infty}
%% \sum_{k=1}^n \frac{1}{k^2} = \frac{\pi^2}{6}
%% \]


这里假设n个16位有符号数累加

\begin{equation}
  S_i + \overline{S_i} = 1, -S_i = \overline{S_i} - 1
\end{equation}

\begin{equation}
-n \cdot 2^{16} = 2^{32} - n \cdot 2^{16} = (2^{16}-n) \cdot 2^{16}
\end{equation}

\begin{equation}
\begin{aligned}
Sum(ext\textrm{ }sign) = \sum_{i=16}^{31} S_0 \cdot {2^i} + \sum_{i=16}^{31} S_1 \cdot {2^i} + \cdots + \sum_{i=16}^{31} S_{n-1} \cdot {2^i} \\
= (S_0 + S_1 + \cdots + S_{n-1}) \cdot \sum_{i=16}^{31} 2^i \\
= (S_0 + S_1 + \cdots + S_{n-1}) \cdot (2^{32} - 2^{16}) \\
= ((-S_0) + (-S_1) + \cdots + (-S_{n-1})) \cdot 2^{16} \\
= (\overline{S_0}-1 + \overline{S_1}-1 + \cdots + \overline{S_{n-1}}-1) \cdot 2^{16} \\
= (\overline{S_0} + \overline{S_1} + \cdots + \overline{S_{n-1}}) \cdot 2^{16} + (-n \cdot 2^{16}) \\
= \underline{(\overline{S_0} + \overline{S_1} + \cdots + \overline{S_{n-1}}) \cdot 2^{16} + (2^{16}-n) \cdot 2^{16}}
%% = (\overline{S_0} + \overline{S_1} + \cdots + \overline{S_{n-1}} + 1) \cdot 2^{16} + (2^{16}-1-n) \cdot 2^{16}
\end{aligned}
\end{equation}


%% for 8x8 multiply
\begin{equation}
\begin{aligned}
Sum(sign16) = \sum_{i=9}^{15} S_0 \cdot {2^i} + \sum_{i=11}^{15} S_1 \cdot {2^i} + \sum_{i=13}^{15} S_2 \cdot {2^i} + \sum_{i=15}^{15} S_3 \cdot {2^i} \\
= S_0 \cdot (2^{16}-2^9) + S_1 \cdot (2^{16}-2^{11}) + S_2 \cdot (2^{16}-2^{13}) + S_3 \cdot (2^{16}-2^{15}) \\
= (-S_0 \cdot 2^9) + (-S_1 \cdot 2^{11}) + (-S_2 \cdot 2^{13}) + (-S_3 \cdot 2^{15}) \\
= (\overline{S_0}-1) \cdot 2^9 + (\overline{S_1}-1) \cdot 2^{11} + (\overline{S_2}-1) \cdot 2^{13} + (\overline{S_3}-1) \cdot 2^{15}  \\
= \underline{(\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) - (2^9 + 2^{11} + 2^{13} + 2^{15})} \\
= (\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^{16} - (2^9 + 2^{11} + 2^{13} + 2^{15})) \\
= \underline{(\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^9 + 2^{10} + 2^{12} + 2^{14})}
\end{aligned}
\end{equation}

%% for 8x8 multiply (ext to 32 bit)
\begin{equation}
\begin{aligned}
Sum(sign32) = \sum_{i=9}^{31} S_0 \cdot {2^i} + \sum_{i=11}^{31} S_1 \cdot {2^i} + \sum_{i=13}^{31} S_2 \cdot {2^i} + \sum_{i=15}^{31} S_3 \cdot {2^i} \\
= S_0 \cdot (2^{32}-2^9) + S_1 \cdot (2^{32}-2^{11}) + S_2 \cdot (2^{32}-2^{13}) + S_3 \cdot (2^{32}-2^{15}) \\
= (-S_0 \cdot 2^9) + (-S_1 \cdot 2^{11}) + (-S_2 \cdot 2^{13}) + (-S_3 \cdot 2^{15}) \\
= (\overline{S_0}-1) \cdot 2^9 + (\overline{S_1}-1) \cdot 2^{11} + (\overline{S_2}-1) \cdot 2^{13} + (\overline{S_3}-1) \cdot 2^{15} \\
= \underline{(\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) - (2^9 + 2^{11} + 2^{13} + 2^{15})} \\
= (\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^{32} - (2^9 + 2^{11} + 2^{13} + 2^{15})) \\
= (\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^{31}+2^{30}+\cdots+2^{16})+(2^{16}- (2^9 + 2^{11} + 2^{13} + 2^{15})) \\
= \underline{(\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^9 + 2^{10} + 2^{12} + 2^{14}) + (2^{15}+2^{14}+\cdots+2^{0}) \cdot 2^{16}}
\end{aligned}
\end{equation}


%% for 8x8 multiply and negate (-a*b, ext to 32 bit)
\begin{equation}
\begin{aligned}
Sum(sign _ negate) = (\sum_{i=9}^{31} S_0 \cdot {2^i} + \sum_{i=11}^{31} S_1 \cdot {2^i} + \sum_{i=13}^{31} S_2 \cdot {2^i} + \sum_{i=15}^{31} S_3 \cdot {2^i}) + \sum_{i=16}^{31} S_4 \cdot {2^i} \\
= (\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^9 + 2^{10} + 2^{12} + 2^{14}) + (2^{15}+ \cdots + 2^1 + 2^0) \cdot 2^{16} + \sum_{i=16}^{31} S_4 \cdot {2^i} \\
= (\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^9 + 2^{10} + 2^{12} + 2^{14}) + (2^{15}+ \cdots + 2^1 + (1+ \sum_{i=0}^{15} S_4 \cdot 2^i)) \cdot 2^{16}
\end{aligned}
\end{equation}

\begin{equation}
\begin{aligned}
(\sum_{i=0}^{15} S_4 \cdot {2^i} + 1) \cdot 2^{16} \\
= (S_4 \cdot (2^{15} + \cdots + 2^1 + 1) + 1) \cdot 2^{16} \\
= (S_4 \cdot (2^{15} + \cdots + 2^1 + 1) + S_4 + \overline{S_4}) \cdot 2^{16} \\
= (S_4 \cdot (2^{15} + \cdots + 2^1 + 1 + 1) + \overline{S_4}) \cdot 2^{16} \\
= \overline{S_4} \cdot 2^{16}
\end{aligned}
\end{equation}

\begin{equation}
\begin{aligned}
Sum(sign _ negate) = (\overline{S_0} \cdot 2^9 + \overline{S_1} \cdot 2^{11} + \overline{S_2} \cdot 2^{13} + \overline{S_3} \cdot 2^{15}) + (2^9 + 2^{10} + 2^{12} + 2^{14}) + (2^{15}+ \cdots + 2^{1}+\overline{S_4}) \cdot 2^{16}
\end{aligned}
\end{equation}


%% \begin{equation}
%%   a^x+y \neq a^{x+y}
%% \end{equation}

%% %% use \label & \ref to reference fomula
%% \begin{equation} \label{eq:eps}
%%   \epsilon > 0
%% \end{equation}

%% From (\ref{eq:eps}), we gather \ldots


%% %% overline
%% $ F = \overline{A+B} \cdot C $
%% $ \underline{m+n} $

%% $S = \underbrace{a+b+\cdots+z}_{26}$



%% \[
%% \alpha, \beta, \gamma, \Omega
%% \]



%% \[
%% \phi = \sum^\infty_{t=0}\beta^t U(c_t,x_t)\mbox{}
%% \]

%% $\sum^\infty_{t=0}\alpha^t$

%% $c^{2}=a^{2}+b^{2}$

%% $d^2=a^2+b^2$

%% \[
%% S = \sum^31_{t=0}
%% \]

%% this $is$ $\heartsuit$


%% \begin{displaymath}
%%   c^2 = a^2 + b^2
%% \end{displaymath}
  


\end{document}

